package com.gopay.checkorder.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.gopay.checkorder.common.BankLock;
import com.gopay.checkorder.service.BankOrderService;
import com.gopay.common.Result;
import com.gopay.common.constants.bank.BisBankBusinessProd;
import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.bank.BankOrder;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.dayend.BaseDayendEntry;
import com.gopay.common.domain.cps.vo.CheckOrderResult;

/**
 * 对单Service实现
 * 
 * @BankOrderServiceImpl.java
 * @author yaobo
 * @2013-3-20 上午10:04:17 www.gopay.com.cn Inc.All rights reserved.
 */
@Service("bankOrderService")
public class BankOrderServiceImpl implements BankOrderService {
    private final static Logger logger = LoggerFactory.getLogger("CHECK_ORDER");

//    private Object synObj = new Object();

    @Resource(name = "checkOrderProxy")
    private BankOrderService checkOrderProxy;

    @Override
    public CheckOrderResult checkOrder(BankOrder bankOrder, String target) {
        CheckOrderResult checkOrderResult = new CheckOrderResult();
        logger.error("BankOrder:" + bankOrder);

        if (bankOrder == null) {
            checkOrderResult.setErrCode(ProcCodeConstants.PROC_CODE_100E5060);
            checkOrderResult.setErrMsg("bankOrder is null.");

            logger.error("bankOrder is null.");
            return checkOrderResult;
        }
//        if (StringUtils.equals(bankOrder.getBankCode(), "ICBC")) {
//            // 由于工行前置机KEY不支持并发，只能将工行改为单线程处理
//            synchronized (synObj) {
//                
//                    if (!BankLock.exist(bankOrder.getBankCode(), bankOrder.getOrderId())) {
//                        // 对单
//                        checkOrderResult = checkOrderProxy.checkOrder(bankOrder, target);
//
//                        BankLock.delete(bankOrder.getBankCode());
//                    }
//            }
//        } else {
            // 对单
            checkOrderResult = checkOrderProxy.checkOrder(bankOrder, target);
//        }

        return checkOrderResult;
    }

    public void setCheckOrderProxy(BankOrderService checkOrderProxy) {
        this.checkOrderProxy = checkOrderProxy;
    }


	@Override
	public BankOrder getDbOrder() {
		// TODO Auto-generated method stub
		return null;
	}



	@Override
	public List<CheckOrderResult> checkDayend(String bank_bus) {
		return checkOrderProxy.checkDayend(bank_bus);
	}

	@Override
	public BaseMessage dayend(String bank_bus) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Result getDayendMsg(String string) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public CheckOrderResult checkDayendOrder(BaseDayendEntry bdm, BankOrder bo) {
		// TODO Auto-generated method stub
		return null;
	}

}
